﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Aletfa.LightManager
{
    /// <summary>
    /// Interaction logic for UnitViewerControl.xaml
    /// </summary>
    public partial class UnitViewerControl : UserControl
    {
        public UnitViewerControl()
        {
            InitializeComponent();
        }

        public Unit Datasource
        {
            get { return this.Tag as Unit; }
            set
            {
                this.Tag = value;
                this.IsEnabled = (value != null);
                if (value == null) return;
                this.pnlLife.Children.Clear();
                int column = 0;
                int row = 0;
                foreach (WoundType life in value.LifeStatus)
                {
                    Image image = new Image();
                    if (life == WoundType.Aggravated)
                        image.Source = this.imgAggravate.Source;
                    if (life == WoundType.Wounded)
                        image.Source = this.imgWounded.Source;
                    if (life == WoundType.Free)
                        image.Source = this.imgFull.Source;
                    image.Width = image.Height = 16;
                    this.pnlLife.Children.Add(image);
                    Grid.SetColumn(image, column++);
                    Grid.SetRow(image, row);

                    if (column == 5)
                        column++;

                    if (column > 10)
                    {
                        row++;
                        column = 0;
                        this.pnlLife.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });
                    }
                }
            }
        }
    }
}
